package com.ruoyi.web.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.web.domain.QgPayBusiness;
import com.ruoyi.web.enums.CommonDictEnum;
import com.ruoyi.web.enums.QGPayBusinessEnum;
import com.ruoyi.web.mapper.QgPayBusinessMapper;
import com.ruoyi.web.service.IQgPayBusinessService;
import com.ruoyi.web.utils.CommonUtil;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * QGPay业务Service业务层处理
 *
 * @date 2023-03-15
 */
@Service
@AllArgsConstructor
public class QgPayBusinessServiceImpl implements IQgPayBusinessService {
    private final QgPayBusinessMapper qgPayBusinessMapper;
    private final CommonUtil commonUtil;

    /**
     * 查询QGPay业务
     *
     * @param id QGPay业务主键
     * @return QGPay业务
     */
    @Override
    public QgPayBusiness selectQgPayBusinessById(Long id) {
        return qgPayBusinessMapper.selectQgPayBusinessById(id);
    }

    /**
     * 查询QGPay业务列表
     *
     * @param qgPayBusiness QGPay业务
     * @return QGPay业务
     */
    @Override
    public List<QgPayBusiness> selectQgPayBusinessList(QgPayBusiness qgPayBusiness) {
        List<QgPayBusiness> list = qgPayBusinessMapper.selectQgPayBusinessList(qgPayBusiness);

        // 遍历
        list.forEach(i -> {
            // 翻译字典项
            i.setType(QGPayBusinessEnum.Type.findName(i.getType()));
            i.setStatus(CommonDictEnum.Status.findName(i.getStatus()));
        });

        return list;
    }

    /**
     * 新增QGPay业务
     *
     * @param qgPayBusiness QGPay业务
     * @return 结果
     */
    @Override
    public int insertQgPayBusiness(QgPayBusiness qgPayBusiness) {
        commonUtil.initCreateAbout(qgPayBusiness);
        return qgPayBusinessMapper.insertQgPayBusiness(qgPayBusiness);
    }

    /**
     * 修改QGPay业务
     *
     * @param qgPayBusiness QGPay业务
     * @return 结果
     */
    @Override
    public int updateQgPayBusiness(QgPayBusiness qgPayBusiness) {
        qgPayBusiness.setUpdateTime(DateUtils.getNowDate());
        return qgPayBusinessMapper.updateQgPayBusiness(qgPayBusiness);
    }

    /**
     * 批量删除QGPay业务
     *
     * @param ids 需要删除的QGPay业务主键
     * @return 结果
     */
    @Override
    public int deleteQgPayBusinessByIds(Long[] ids) {
        return qgPayBusinessMapper.deleteQgPayBusinessByIds(ids);
    }

    /**
     * 删除QGPay业务信息
     *
     * @param id QGPay业务主键
     * @return 结果
     */
    @Override
    public int deleteQgPayBusinessById(Long id) {
        return qgPayBusinessMapper.deleteQgPayBusinessById(id);
    }

    /**
     * 选项
     *
     * @param condition 查询条件
     * @return {@link List< QgPayBusiness>}
     * @since 2023/3/26 16:34
     */
    @Override
    public List<QgPayBusiness> optionList(QgPayBusiness condition) {
        condition.setStatus(CommonDictEnum.Status.NORMAL.getValue());
        List<QgPayBusiness> list = qgPayBusinessMapper.optionList(condition);

        // 遍历
        list.forEach(i -> {
            // 翻译字典项
            i.setType(QGPayBusinessEnum.Type.findName(i.getType()));
        });

        return list;
    }
}
